var orderStatus = 0;
var status = 0;

$(function(){
    $("#edit").attr("disabled",false);
});

	$("#np").click(function(){
        orderStatus = 0;
        status = 0;
        $("#table").bootstrapTable('refresh');
        $("#edit").attr("disabled",false);
	});

	$("#ns").click(function(){
       orderStatus = 1;
       status = 0;
        $("#table").bootstrapTable('refresh');
        $("#edit").attr("disabled",false);
	});

	$("#nr").click(function(){
        orderStatus = 1;
        status = 1;
        $("#table").bootstrapTable('refresh');
        $("#edit").attr("disabled",true);
	});

	$("#af").click(function(){
        orderStatus = 1;
        status = 2;
        $("#table").bootstrapTable('refresh');
        $("#edit").attr("disabled",true);
	});


	$("#shopTypeId").change(function () {
		$("#table").bootstrapTable('refresh');
	});


//发货
function send(orderId,shopId){
//	alert("aa-"+orderId+"----"+shopId);
	$.post("updateOrderDetailStatus",{
		orderId : orderId,
		shopId : shopId,
		status : 1
	},function(data){
		if(data.code == 200){
			layer.msg(data.msg, {icon : 1,time : 1500});
			setTimeout(function(){
				$("#table").bootstrapTable('refresh');
			},1500);
		}else{
			layer.msg(data.msg, {icon : 2,time : 1500});
		}
	},"json");
}


//修改 查看
$("#edit").click(function() {
	var ids = getSelections(); 
	var orderList = getSelectionss(); 
	if (ids.length == 1) {
		// 根据id 查询信息 
		$("input[name=orderId]").val(orderList[0].order_id);
		$("input[name=reName]").val(orderList[0].re_name);
		$("input[name=rePhone]").val(orderList[0].re_phone);
		$("input[name=reAdd]").val(orderList[0].re_add);
		$("input[name=reId]").val(orderList[0].re_id);
	
		$('#modal-edit').modal('toggle');
	}else if(ids.length == 0){
		layer.msg("未选择数据");
	}else{
		layer.msg("请勿勾选多个");
	}
});

//确认修改
$("#editBtn").click(function(){
	
	var orderId = $("#orderId").val();
	var reId = $("#reId").val();
	var reName = $("#reName").val();
	var rePhone = $("#rePhone").val();
	var reAdd = $("#reAdd").val();
	
	$.post("updateReceiveGood",
		{orderId : orderId,reId : reId,reName : reName,rePhone : rePhone,reAdd : reAdd},
		function(data){
			if(data.code == 200){
				layer.msg("修改成功", {icon : 1,time : 1500,});
			}else{
				layer.msg("修改失败", {icon : 2,time : 1500,});
			}
		},"json");
});


//删除 deleteBtn
$("#deleteBtn").click(function(){
	var ids = getSelections(); 
	if(ids.length == 0){
		layer.msg("未选择数据");
	}else{
		layer.msg("删除成功", {icon : 1,time : 1500,});
	}
});


function queryParams(p) {
	var userId = $("#userId").val();
	p.userId = userId;
    p.shopTypeId = $('#shopTypeId option:selected').val();
	p.orderStatus = orderStatus;
	p.status = status;
	return p;

}


function getSelections() {
	return $.map($('#table').bootstrapTable('getSelections'),function(row) {
		return row.order_id;
	});
}

function getSelectionss() {
	return $.map($('#table').bootstrapTable('getSelections'),function(row) {
		return row;
	});
}


function statu(value, row, index) {
	var ostatus = row.order_status;
	var status = row.status;
	var orderId = row.order_id;
	var shopId = row.shop_id;
	if(ostatus == 0 && status == 0){
		return [
			"<span style='color: #1818f5;'>待付款</span>"
		].join('');	
	}
	if(ostatus == 1 && status == 0){
		return [
			"<span style='color: #6d9eeb;'>已付款，代发货 &nbsp;<button onclick='send("+orderId+","+shopId+")' style='color: #000000;'>发货</button></span>"
		].join('');	
	}
	if(ostatus == 1 && status == 1){
		return [
			"<span style='color: #6d9eeb;'>已发货，代收货</span>"
		].join('');	
	}
	if(ostatus == 1 && status == 2){
		return [
			"<span style='color: #6d9eeb;'>已完成</span>"
		].join('');	
	}
}
